package com.blockmeta.bbs.immodule.widget.msgview;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;

import com.blockmeta.bbs.baselibrary.utils.LoadPicUtil;
import com.blockmeta.bbs.immodule.R;
import com.blockmeta.bbs.immodule.bean.databean.KlineContentBean;
import com.blockmeta.bbs.immodule.dao.ChatMessage;
import com.chad.library.adapter.base.BaseViewHolder;

public class KlineMsgView<T extends ChatMessage> extends MsgView<T>{

    public KlineMsgView(Context context) {
        super(context);
    }

    @Override
    public int getLayoutId() {
        return R.layout.im_chat_kline;
    }

    @Override
    public void convert(BaseViewHolder helper, T item, T lastItem) {
        super.convert(helper, item, lastItem);
        super.bindCommonControl(helper, item, lastItem);

        KlineContentBean contentBean = getContentBean(item, KlineContentBean.class);
        if (contentBean==null){
            return;
        }
        String deepLink = String.format("blockmeta://market/kline?coin=%s&currency=%s&exchange=%s"
                , contentBean.getCoin().toLowerCase(), contentBean.getCurrency().toLowerCase(), contentBean.getExchange());
        //发送消息！
        String title = (contentBean.getCoin() + "/" + contentBean.getCurrency()).toUpperCase();
        String change;
        if (item.getType() == ChatMessage.TYPE_SEND) {
            ImageView icon = helper.getView(R.id.right_img_icon);
            LoadPicUtil.loadWithPicasso(icon, contentBean.getImg());
            helper.setText(R.id.right_pair_name, title);
            helper.setText(R.id.right_price, "$" + contentBean.getPrice());
            helper.setText(R.id.right_change, contentBean.getChange());
            change = contentBean.getChange();
            if(!TextUtils.isEmpty(change)&&change.startsWith("-")){
                helper.setBackgroundRes(R.id.right_change, R.drawable.shape_round_corner_red_ee4a45);
            }else {
                helper.setBackgroundRes(R.id.right_change, R.drawable.shape_round_corner_green_29b32a);
            }
            View contentLayout = helper.getView(R.id.chat_item_layout_content);
            contentLayout.setTag(deepLink);
            helper.addOnClickListener(R.id.chat_item_layout_content);
        } else {
            //接收消息
            ImageView icon = helper.getView(R.id.left_img_icon);
            LoadPicUtil.loadWithPicasso(icon, contentBean.getImg());
            helper.setText(R.id.left_pair_name, title);
            helper.setText(R.id.left_price, "$" + contentBean.getPrice());
            helper.setText(R.id.left_change, contentBean.getChange());
            change = contentBean.getChange();
            if(!TextUtils.isEmpty(change)&&change.startsWith("-")){
                helper.setBackgroundRes(R.id.left_change, R.drawable.shape_round_corner_red_ee4a45);
            }else {
                helper.setBackgroundRes(R.id.left_change, R.drawable.shape_round_corner_green_29b32a);
            }
            View contentLayout = helper.getView(R.id.left_chat_item_layout_content);
            contentLayout.setTag(deepLink);
            helper.addOnClickListener(R.id.left_chat_item_layout_content);
        }

    }

}
